﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WordWonderGame.Business;
using System.Media;

namespace WordWonderGame.UI.Man3
{
    public partial class FormMan3 : UserControl
    {
        TraLoiUI traloiUI;
        TimerMan3 timerUI;
        int CauHoiHienTai=1;
        public event EventHandler QuaMan3Roi;
        List<CauHoiMan3> listCauhoiMan3;
        public FormMan3()
        {
            InitializeComponent();
            //traloiUI
            
            traloiUI = new TraLoiUI();
            traloiUI.Dock = DockStyle.Fill;
            traloiUI.Parent = pnTraLoi;
            traloiUI.Visible = false;
            traloiUI.TraloiSaiCauNay += new EventHandler(traloiUI_TraloiSaiCauNay);
            traloiUI.TraloiDungCauNay += new EventHandler(traloiUI_TraloiDungCauNay);
            //TimerUI
            timerUI = new TimerMan3();
            timerUI.Dock = DockStyle.Fill;
            timerUI.Parent = pnKetQua;
            timerUI.Visible = false;
            timerUI.LoadCauHoiMoi += new EventHandler(timerUI_LoadCauHoiMoi);
            timerUI.HetGio += new EventHandler(timerUI_HetGio);
            //timerUI.HetGio+=new EventHandler(timerUI_HetGio);
            //listCauhoiMan3
            listCauhoiMan3 = new List<CauHoiMan3>();
        }

        public void HetGioChoMan3()
        {
            timerUI.thoiGianHienTai = 10;
        }

        void timerUI_HetGio(object sender, EventArgs e)
        {
            //
            traloiUI.HienThiCauSai();
            timerUI.SaiCauNay(CauHoiHienTai);
            CauHoiHienTai++;
            traloiUI.LoadTraLoi();

        }

        void timerUI_LoadCauHoiMoi(object sender, EventArgs e)
        {
            if (CauHoiHienTai > 7)
            {
                if (QuaMan3Roi != null)
                {
                    QuaMan3Roi(timerUI.Diem, null);
                }
            }
            else
            {
                traloiUI.BindCauHoi(listCauhoiMan3[CauHoiHienTai - 1].CauHoi);

                timerUI.Restart();
            }
        }

        void traloiUI_TraloiDungCauNay(object sender, EventArgs e)
        {
            timerUI.DungCauNay(CauHoiHienTai);
            if (CauHoiHienTai == 7)
            {
                CauHoiHienTai++;
            }
            else
            {
                CauHoiHienTai++;
            }
        }

        void traloiUI_TraloiSaiCauNay(object sender, EventArgs e)
        {
            timerUI.SaiCauNay(CauHoiHienTai);
            if (CauHoiHienTai == 7)
            {
                CauHoiHienTai++;
            }
            else
            {
                CauHoiHienTai++;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SoundPlayer playerbutton = new SoundPlayer(@"Sound\button_click.wav");
            playerbutton.Play();
            button1.Visible = false;
            traloiUI.Visible = true;
            timerUI.Visible = true;

            DataClassDAL dataClass = new DataClassDAL();
            listCauhoiMan3 = dataClass.Lay7CauHoiMan3();
            traloiUI.BindCauHoi(listCauhoiMan3[CauHoiHienTai - 1].CauHoi);
        }
    }
}
